package cn.zcf.user.controller;

import cn.zcf.basic.exception.BusinessException;
import cn.zcf.basic.utils.JsonResult;
import cn.zcf.org.dto.UserDto;
import cn.zcf.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;
    //用户注册
    @PostMapping("/register/phone")
    public JsonResult register(@RequestBody UserDto userDto){
        try {
            userService.phoneRegister(userDto);
            return JsonResult.me();
        }
        catch (BusinessException e){
            e.printStackTrace();
            return JsonResult.me().setMsg("注册失败!"+e.getMessage());
        }
        catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("系统错误!"+e.getMessage());
        }
    }
}
